package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.FileInfo;
import com.lemon.smartsafetynew.ui.activity.record.RecordBaseInfoActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/31.
 */

public class FilesAdapter extends LemonRcvAdapter<FileInfo> {
    private RecyclerTClickListener<FileInfo> mListener;

    public FilesAdapter(@Nullable List<FileInfo> data, RecyclerTClickListener<FileInfo> mListener) {
        super(data);
        this.mListener = mListener;
    }


    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new FilesAdapter.FileItem();
    }

    public class FileItem implements AdapterItem<FileInfo> {
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        @Bind(R.id.file_name)
        TextView fileName;
        private FileInfo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_file_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(FileInfo fileInfo, int position) {
            data = fileInfo;
            pos = position;
            fileName.setText(fileInfo.getName());
        }
    }
}

